<?php

namespace App\Domain\HealthHistory\Controllers;

use App\Domain\HealthHistory\Requests\AllergyPost;
use App\Domain\HealthHistory\Requests\OperationPost;
use App\Domain\HealthHistory\Services\HealthHistoryService;
use App\Http\Controllers\Controller;
use App\Domain\HealthHistory\Requests\DiseasePost;

class HealthHistoryController extends Controller
{
    //手术史
    public function healthHistoryOperation(OperationPost $request, HealthHistoryService $healthHistoryService)
    {
        $param = $request->validated();
        if ($param['type'] == 0) {
            $result = $healthHistoryService->findByOperationUid($param['memberUid']);
            return $this->success($result);
        } else {
            $result = $healthHistoryService->Operation($param);
            return $this->success();
        }
    }


    //过往病史（家庭病史）
    public function healthHistoryDisease(DiseasePost $request, HealthHistoryService $healthHistoryService)
    {
        $param = $request->validated();
        if ($param['type'] == 0) {
            $result = $healthHistoryService->findByDiseaseUidAndWhere($param);
            return $this->success($result);
        } else {
            $result = $healthHistoryService->Disease($param);
            return $this->success();
        }
    }

    //过敏史
    public function healthHistoryAllergy(AllergyPost $request, HealthHistoryService $healthHistoryService)
    {
        $param = $request->validated();
        if ($param['type'] == 0) {
            $result = $healthHistoryService->findByAllergyUid($param['memberUid']);
            return $this->success($result);
        } else {
            $result = $healthHistoryService->Allergy($param);
            return $this->success();
        }
    }
}
